<template>
	<view class="content">		
		<view class="list">
			<view class="list_one" v-for="item in mycards" @click="unBand(item.cardid)">
				<view class="one_head">
					{{item.head}}
				</view>
				<view class="one_cont">
					<view class="one_tit">
						{{item.body}}
					</view>
					<view class="one_dec">
						{{item.date}}
					</view>
				</view>
			</view>
		</view>
		<u-toast ref="uToast" />
		<view>
			<u-modal title="解绑小程序码" @confirm="confirm" v-model="showConfim" :content="confimContent" show-cancel-button="false"></u-modal>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				showConfim:false,
				confimContent:'确定解绑当前小程序码吗？解绑后可再次绑定',
				mycards:[],
				cardid:''
			}
		},
		onLoad(){
			this.islogin();
			this.initData();
		},
		methods: {
			islogin(){
				const openid=uni.getStorageSync('openid');
				if(!openid){
					this.$refs.uToast.show({
						title: '未登录',
						type: 'warning',
					})
					setTimeout(()=>{
						uni.navigateTo({
							url:'../home/home'
						})
					},2000)
					return;
				}
			},
			initData(){
				uni.showLoading()
				const openid=uni.getStorageSync('openid');
				uni.request({
					url:this.$config.baseApi+'user/mycard',
					data:{openid},
					method:'POST',
					dataType:'json',
					success: (res) => {
						uni.hideLoading();
						const cardsData=res.data;
						if(!cardsData.code){
							this.$refs.uToast.show({
								title: cardsData.msg,
								type: 'error',
							})
							this.mycards=[];
							return;
						}
						this.mycards=cardsData.data;
					}
				})
			},
			unBand(cardid){
				this.cardid=cardid;
				this.showConfim=true
			},
			confirm(){
				uni.request({
					url:this.$config.baseApi+'card/uncardband',
					data:{cardid:this.cardid},
					method:'POST',
					dataType:'json',
					success: (res) => {
						const cardsData=res.data;
						if(!cardsData.code){
							this.$refs.uToast.show({
								title: cardsData.msg,
								type: 'error',
							})
							return;
						}
						this.$refs.uToast.show({
							title: cardsData.msg,
							type: 'success',
						})
						setTimeout(()=>{
							this.initData();
						},2000)
					}
				})
			}
		}
	}
</script>

<style>
	page{
		background: #e4e4e4; 
		
	}
	.header{
		font-size: 34rpx;
		text-align: center;
		padding: 20rpx;
		color: #303133;
		background-color: white;
	}
	.list{
		width: 100%;
		padding: 20rpx;
	}
	.list_one{
		display: flex;
		margin-bottom: 20rpx;
		padding: 20rpx;
		background-color: white;
		box-sizing:content-box;
		border-radius: 8rpx;
	}
	.one_head{
		width: 80rpx;
		height: 80rpx;
		border-radius: 40rpx;
		background-color: #007AFF;
		color: white;
		text-align: center;
		line-height: 80rpx;
		font-size: 40rpx;
		margin-right: 40rpx;
	}
	.one_cont{
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	.one_tit{
		font-size: 36rpx;
		letter-spacing: 4rpx;
	}
	.one_dec{
		color: #999;
	}
</style>
